<%--
  Created by IntelliJ IDEA.
  User: 杨娇
  Date: 2025/6/25
  Time: 9:39
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>绿能充 - 编辑用户</title>
    <link href="https://fonts.googleapis.com/css2?family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta3/css/all.min.css">
    <style>
        :root {
            --primary-color: #00a896;
            --secondary-color: #02c39a;
            --dark-color: #05668d;
            --light-color: #f0f3bd;
            --accent-color: #028090;
            --text-dark: #333;
            --text-light: #f8f9fa;
            --shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
            --transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
        }

        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

        body {
            font-family: 'Noto Sans SC', sans-serif;
            color: var(--text-dark);
            background-color: #f9f9f9;
            min-height: 100vh;
            display: flex;
        }

        /* 侧边栏样式 - 与dashboard一致 */
        .sidebar {
            width: 250px;
            background: linear-gradient(135deg, var(--dark-color) 0%, var(--primary-color) 100%);
            color: white;
            padding: 20px 0;
            height: 100vh;
            position: fixed;
            box-shadow: var(--shadow);
            z-index: 100;
        }

        .sidebar-header {
            padding: 0 20px 20px;
            border-bottom: 1px solid rgba(255, 255, 255, 0.1);
            margin-bottom: 20px;
        }

        .sidebar-header .logo {
            display: flex;
            align-items: center;
            margin-bottom: 15px;
        }

        .sidebar-header .logo-icon {
            width: 40px;
            height: 40px;
            background-color: rgba(255, 255, 255, 0.2);
            border-radius: 50%;
            display: flex;
            align-items: center;
            justify-content: center;
            margin-right: 10px;
            font-size: 18px;
            color: var(--light-color);
        }

        .sidebar-header h3 {
            font-size: 1.2rem;
            font-weight: 500;
            margin: 0;
        }

        .sidebar-header p {
            font-size: 0.8rem;
            opacity: 0.8;
            margin: 0;
        }

        .nav-menu {
            list-style: none;
            padding: 0 15px;
        }

        .nav-item {
            margin-bottom: 5px;
        }

        .nav-link {
            display: flex;
            align-items: center;
            padding: 12px 15px;
            color: rgba(255, 255, 255, 0.8);
            text-decoration: none;
            border-radius: 8px;
            transition: var(--transition);
        }

        .nav-link:hover, .nav-link.active {
            background-color: rgba(255, 255, 255, 0.1);
            color: white;
        }

        .nav-link i {
            margin-right: 10px;
            width: 20px;
            text-align: center;
            font-size: 16px;
        }

        .nav-link .badge {
            margin-left: auto;
            background-color: var(--light-color);
            color: var(--dark-color);
            font-size: 0.7rem;
            padding: 3px 6px;
        }

        .user-profile {
            position: absolute;
            bottom: 20px;
            left: 0;
            width: 100%;
            padding: 0 20px;
        }

        .user-info {
            display: flex;
            align-items: center;
            padding: 10px;
            background-color: rgba(255, 255, 255, 0.1);
            border-radius: 8px;
            cursor: pointer;
            transition: var(--transition);
        }

        .user-info:hover {
            background-color: rgba(255, 255, 255, 0.2);
        }

        .user-avatar {
            width: 36px;
            height: 36px;
            border-radius: 50%;
            background-color: rgba(255, 255, 255, 0.2);
            display: flex;
            align-items: center;
            justify-content: center;
            margin-right: 10px;
            font-size: 14px;
        }

        .user-name {
            font-size: 0.9rem;
            font-weight: 500;
            margin-bottom: 2px;
        }

        .user-role {
            font-size: 0.7rem;
            opacity: 0.8;
        }

        /* 主内容区样式 */
        .main-content {
            flex: 1;
            margin-left: 250px;
            padding: 30px;
        }

        .header {
            display: flex;
            justify-content: space-between;
            align-items: center;
            margin-bottom: 30px;
        }

        .page-title h1 {
            font-size: 1.8rem;
            font-weight: 600;
            color: var(--dark-color);
            margin-bottom: 5px;
        }

        .page-title p {
            color: #777;
            font-size: 0.9rem;
            margin: 0;
        }

        .header-actions {
            display: flex;
            gap: 10px;
        }

        .btn {
            padding: 8px 16px;
            border-radius: 8px;
            font-size: 0.9rem;
            font-weight: 500;
            border: none;
            cursor: pointer;
            transition: var(--transition);
            display: flex;
            align-items: center;
        }

        .btn i {
            margin-right: 6px;
        }

        .btn-primary {
            background: linear-gradient(to right, var(--primary-color), var(--secondary-color));
            color: white;
            box-shadow: 0 4px 15px rgba(0, 168, 150, 0.3);
        }

        .btn-primary:hover {
            transform: translateY(-2px);
            box-shadow: 0 8px 20px rgba(0, 168, 150, 0.4);
        }

        .btn-outline {
            background: transparent;
            border: 1px solid #ddd;
            color: #555;
        }

        .btn-outline:hover {
            background-color: #f5f5f5;
        }

        .btn-danger {
            background: linear-gradient(to right, #f44336, #ff9800);
            color: white;
            box-shadow: 0 4px 15px rgba(244, 67, 54, 0.3);
        }

        .btn-danger:hover {
            transform: translateY(-2px);
            box-shadow: 0 8px 20px rgba(244, 67, 54, 0.4);
        }

        /* 表单卡片样式 */
        .form-card {
            background-color: white;
            border-radius: 12px;
            box-shadow: var(--shadow);
            padding: 30px;
            margin-bottom: 30px;
        }

        .form-header {
            margin-bottom: 25px;
            padding-bottom: 15px;
            border-bottom: 1px solid #eee;
        }

        .form-header h3 {
            font-size: 1.3rem;
            font-weight: 600;
            color: var(--dark-color);
            margin: 0;
        }

        .form-group {
            margin-bottom: 20px;
        }

        .form-row {
            display: flex;
            gap: 20px;
            margin-bottom: 20px;
        }

        .form-col {
            flex: 1;
        }

        .form-label {
            display: block;
            margin-bottom: 8px;
            font-size: 0.9rem;
            color: #555;
            font-weight: 500;
        }

        .form-control {
            width: 100%;
            padding: 10px 15px;
            border: 1px solid #ddd;
            border-radius: 8px;
            font-size: 0.9rem;
            transition: var(--transition);
        }

        .form-control:focus {
            border-color: var(--primary-color);
            outline: none;
            box-shadow: 0 0 0 3px rgba(0, 168, 150, 0.1);
        }

        .form-select {
            appearance: none;
            background-image: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3e%3cpolyline points='6 9 12 15 18 9'%3e%3c/polyline%3e%3c/svg%3e");
            background-repeat: no-repeat;
            background-position: right 10px center;
            background-size: 1em;
        }

        .form-text {
            font-size: 0.8rem;
            color: #777;
            margin-top: 5px;
        }

        .form-footer {
            display: flex;
            justify-content: flex-end;
            gap: 15px;
            margin-top: 30px;
            padding-top: 20px;
            border-top: 1px solid #eee;
        }

        /* 角色和状态选择样式 */
        .radio-group {
            display: flex;
            gap: 20px;
        }

        .radio-option {
            display: flex;
            align-items: center;
        }

        .radio-option input {
            margin-right: 8px;
        }

        /* 头像上传区域 */
        .avatar-upload {
            display: flex;
            align-items: center;
            gap: 20px;
        }

        .avatar-preview {
            width: 80px;
            height: 80px;
            border-radius: 50%;
            background-color: #f5f5f5;
            display: flex;
            align-items: center;
            justify-content: center;
            overflow: hidden;
            border: 1px dashed #ddd;
        }

        .avatar-preview img {
            width: 100%;
            height: 100%;
            object-fit: cover;
        }

        .avatar-upload-control {
            flex: 1;
        }

        .avatar-upload-btn {
            display: inline-block;
            padding: 8px 15px;
            background-color: #f5f5f5;
            border-radius: 8px;
            cursor: pointer;
            transition: var(--transition);
            border: 1px solid #ddd;
        }

        .avatar-upload-btn:hover {
            background-color: #eee;
        }

        /* 密码修改区域 */
        .password-change {
            background-color: #f9f9f9;
            border-radius: 8px;
            padding: 15px;
            margin-top: 20px;
            border: 1px solid #eee;
        }

        .password-change-toggle {
            display: flex;
            align-items: center;
            cursor: pointer;
            margin-bottom: 10px;
        }

        .password-change-toggle i {
            margin-right: 8px;
            transition: var(--transition);
        }

        .password-change-toggle.collapsed i {
            transform: rotate(-90deg);
        }

        .password-change-content {
            overflow: hidden;
            transition: max-height 0.3s ease-out;
        }

        .password-change-content.collapsed {
            max-height: 0;
        }

        /* 响应式设计 */
        @media (max-width: 992px) {
            .sidebar {
                width: 70px;
                overflow: hidden;
            }

            .sidebar-header h3,
            .sidebar-header p,
            .nav-link span,
            .user-name,
            .user-role {
                display: none;
            }

            .sidebar-header {
                padding: 15px 10px;
            }

            .nav-link {
                justify-content: center;
                padding: 12px 0;
            }

            .nav-link i {
                margin-right: 0;
                font-size: 18px;
            }

            .main-content {
                margin-left: 70px;
            }
        }

        @media (max-width: 768px) {
            .form-row {
                flex-direction: column;
                gap: 15px;
            }

            .header {
                flex-direction: column;
                align-items: flex-start;
                gap: 15px;
            }
        }

        @media (max-width: 576px) {
            .main-content {
                padding: 20px 15px;
            }

            .form-card {
                padding: 20px;
            }

            .form-footer {
                flex-direction: column;
            }

            .btn {
                width: 100%;
            }
        }
    </style>
</head>
<body>
<!-- 侧边导航栏 -->
<div class="sidebar">
    <div class="sidebar-header">
        <div class="logo">
            <div class="logo-icon">
                <i class="fas fa-charging-station"></i>
            </div>
            <div>
                <h3>绿能充</h3>
                <p>管理员面板</p>
            </div>
        </div>
    </div>

    <ul class="nav-menu">
        <li class="nav-item">
            <a href="/admin/dashboard" class="nav-link">
                <i class="fas fa-tachometer-alt"></i>
                <span>仪表盘</span>
            </a>
        </li>
        <li class="nav-item">
            <a href="/admin/user/list" class="nav-link active">
                <i class="fas fa-users"></i>
                <span>用户管理</span>
                <span class="badge">5</span>
            </a>
        </li>
        <li class="nav-item">
            <a href="/admin/pile/list" class="nav-link">
                <i class="fas fa-charging-station"></i>
                <span>充电桩管理</span>
            </a>
        </li>
        <li class="nav-item">
            <a href="/admin/report/list" class="nav-link">
                <i class="fas fa-list-alt"></i>
                <span>充电记录</span>
            </a>
        </li>
        <li class="nav-item">
            <a href="/admin/fault/list" class="nav-link">
                <i class="fas fa-exclamation-triangle"></i>
                <span>故障报告</span>
                <span class="badge">3</span>
            </a>
        </li>
        <li class="nav-item">
            <a href="/admin/settings" class="nav-link">
                <i class="fas fa-cog"></i>
                <span>系统设置</span>
            </a>
        </li>
    </ul>

    <div class="user-profile">
        <div class="user-info">
            <div class="user-avatar">
                <i class="fas fa-user"></i>
            </div>
            <div>
                <div class="user-name">管理员</div>
                <div class="user-role">超级管理员</div>
            </div>
        </div>
    </div>
</div>

<!-- 主内容区 -->
<div class="main-content">
    <div class="header">
        <div class="page-title">
            <h1>编辑用户</h1>
            <p>修改用户信息</p>
        </div>
        <div class="header-actions">
            <button class="btn btn-outline" onclick="window.history.back()">
                <i class="fas fa-arrow-left"></i> 返回
            </button>
        </div>
    </div>

    <!-- 编辑用户表单 -->
    <div class="form-card">
        <div class="form-header">
            <h3><i class="fas fa-user-edit"></i> 用户信息</h3>
        </div>

        <form action="${pageContext.request.contextPath}/admin/user/edit" method="post">
            <input type="hidden" name="id" value="${user.id}">

            <div class="form-row">
                <div class="form-col">
                    <div class="form-group">
                        <label for="username" class="form-label">用户名 <span class="text-danger">*</span></label>
                        <input type="text" id="username" name="username" class="form-control" value="${user.username}" required>
                        <p class="form-text">用户名必须唯一，长度4-20个字符</p>
                    </div>

                    <div class="password-change">
                        <div class="password-change-toggle" onclick="togglePasswordChange()">
                            <i class="fas fa-chevron-down"></i>
                            <span>修改密码</span>
                        </div>
                        <div class="password-change-content collapsed" id="passwordChangeContent">
                            <div class="form-group">
                                <label for="newPassword" class="form-label">新密码</label>
                                <input type="password" id="newPassword" name="newPassword" class="form-control">
                                <p class="form-text">留空则不修改密码</p>
                            </div>

                            <div class="form-group">
                                <label for="confirmNewPassword" class="form-label">确认新密码</label>
                                <input type="password" id="confirmNewPassword" name="confirmNewPassword" class="form-control">
                            </div>
                        </div>
                    </div>

                    <div class="form-group">
                        <label for="phone" class="form-label">手机号 <span class="text-danger">*</span></label>
                        <input type="tel" id="phone" name="phone" class="form-control" value="${user.phone}" required>
                    </div>

                    <div class="form-group">
                        <label for="email" class="form-label">电子邮箱</label>
                        <input type="email" id="email" name="email" class="form-control" value="${user.email}">
                    </div>
                </div>

                <div class="form-col">
                    <div class="form-group">
                        <label class="form-label">头像</label>
                        <div class="avatar-upload">
                            <div class="avatar-preview" id="avatarPreview">
                                <c:choose>
                                    <c:when test="${not empty user.avatar}">
                                        <img src="${user.avatar}" alt="用户头像">
                                    </c:when>
                                    <c:otherwise>
                                        <i class="fas fa-user" style="font-size: 24px; color: #999;"></i>
                                    </c:otherwise>
                                </c:choose>
                            </div>
                            <div class="avatar-upload-control">
                                <input type="file" id="avatar" name="avatar" accept="image/*" style="display: none;" onchange="previewAvatar(this)">
                                <label for="avatar" class="avatar-upload-btn">
                                    <i class="fas fa-upload"></i> 更换头像
                                </label>
                                <p class="form-text">支持JPG/PNG格式，大小不超过2MB</p>
                            </div>
                        </div>
                    </div>

                    <div class="form-group">
                        <label for="realName" class="form-label">真实姓名</label>
                        <input type="text" id="realName" name="realName" class="form-control" value="${user.realName}">
                    </div>

                    <div class="form-group">
                        <label for="idCard" class="form-label">身份证号</label>
                        <input type="text" id="idCard" name="idCard" class="form-control" value="${user.idCard}">
                    </div>

                    <div class="form-group">
                        <label for="balance" class="form-label">账户余额(元)</label>
                        <input type="number" id="balance" name="balance" class="form-control" value="${user.balance}" step="0.01" min="0">
                    </div>
                </div>
            </div>

            <div class="form-row">
                <div class="form-col">
                    <div class="form-group">
                        <label class="form-label">用户角色 <span class="text-danger">*</span></label>
                        <div class="radio-group">
                            <div class="radio-option">
                                <input type="radio" id="roleUser" name="role" value="0" ${user.role == 0 ? 'checked' : ''}>
                                <label for="roleUser">普通用户</label>
                            </div>
                            <div class="radio-option">
                                <input type="radio" id="roleAdmin" name="role" value="1" ${user.role == 1 ? 'checked' : ''}>
                                <label for="roleAdmin">管理员</label>
                            </div>
                            <div class="radio-option">
                                <input type="radio" id="roleTester" name="role" value="2" ${user.role == 2 ? 'checked' : ''}>
                                <label for="roleTester">测试员</label>
                            </div>
                        </div>
                    </div>
                </div>

                <div class="form-col">
                    <div class="form-group">
                        <label class="form-label">用户状态 <span class="text-danger">*</span></label>
                        <div class="radio-group">
                            <div class="radio-option">
                                <input type="radio" id="statusActive" name="status" value="1" ${user.status == 1 ? 'checked' : ''}>
                                <label for="statusActive">正常</label>
                            </div>
                            <div class="radio-option">
                                <input type="radio" id="statusInactive" name="status" value="0" ${user.status == 0 ? 'checked' : ''}>
                                <label for="statusInactive">禁用</label>
                            </div>
                        </div>
                    </div>
                </div>
            </div>

            <div class="form-footer">
                <button type="reset" class="btn btn-outline">
                    <i class="fas fa-redo"></i> 重置
                </button>
                <button type="submit" class="btn btn-primary">保存用户</button>
            </div>
        </form>
    </div>
</div>

<script>
    // 头像预览功能
    function previewAvatar(input) {
        const preview = document.getElementById('avatarPreview');
        const file = input.files[0];
        const reader = new FileReader();

        reader.onload = function(e) {
            preview.innerHTML = '';
            const img = document.createElement('img');
            img.src = e.target.result;
            preview.appendChild(img);
        }

        if (file) {
            reader.readAsDataURL(file);
        }
    }

    // 密码修改区域切换
    function togglePasswordChange() {
        const content = document.getElementById('passwordChangeContent');
        const toggle = document.querySelector('.password-change-toggle');

        if (content.classList.contains('collapsed')) {
            content.classList.remove('collapsed');
            toggle.classList.remove('collapsed');
            content.style.maxHeight = content.scrollHeight + 'px';
        } else {
            content.classList.add('collapsed');
            toggle.classList.add('collapsed');
            content.style.maxHeight = '0';
        }
    }

    // 密码验证
    document.querySelector('form').addEventListener('submit', function(e) {
        const newPassword = document.getElementById('newPassword').value;
        const confirmNewPassword = document.getElementById('confirmNewPassword').value;

        if (newPassword && newPassword !== confirmNewPassword) {
            e.preventDefault();
            alert('两次输入的新密码不一致，请重新输入！');
            document.getElementById('confirmNewPassword').focus();
        }
    });
</script>
</body>
</html>
